-
Notifications
You must be signed in to change notification settings - Fork 143
selftests/bpf: Change variable types for -Wsign-compare #10045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bpf-next_base
Are you sure you want to change the base?
Conversation
Upstream branch: 7361c86 |
6116807
to
7b565ed
Compare
Upstream branch: 04a8995 |
ca93cce
to
1ce9461
Compare
7b565ed
to
6efc16b
Compare
Upstream branch: 04a8995 |
1ce9461
to
875f270
Compare
6efc16b
to
55beced
Compare
Upstream branch: 96d31df |
875f270
to
308bf54
Compare
55beced
to
b92bbe4
Compare
This is a follow up patch for commit 495d2d8("selftests/bpf: Attempt to build BPF programs with -Wsign-compare") from Alexei Starovoitov[1] to be able to enable -Wsign-compare C compilation flag for clang since -Wall doesn't add it and BPF programs are built with clang.This has the benefit to catch problematic comparisons in future tests as quoted from the commit message:" int i = -1; unsigned int j = 1; if (i < j) // this is false. long i = -1; unsigned int j = 1; if (i < j) // this is true. C standard for reference: - If either operand is unsigned long the other shall be converted to unsigned long. - Otherwise, if one operand is a long int and the other unsigned int, then if a long int can represent all the values of an unsigned int, the unsigned int shall be converted to a long int; otherwise both operands shall be converted to unsigned long int. - Otherwise, if either operand is long, the other shall be converted to long. - Otherwise, if either operand is unsigned, the other shall be converted to unsigned. Unfortunately clang's -Wsign-compare is very noisy. It complains about (s32)a == (u32)b which is safe and doen't have surprising behavior." This specific patch supresses the following warnings when -Wsign-compare is enabled: 1 warning generated. progs/bpf_iter_bpf_percpu_array_map.c:35:16: warning: comparison of integers of different signs: 'int' and 'const volatile __u32' (aka 'const volatile unsigned int') [-Wsign-compare] 35 | for (i = 0; i < num_cpus; i++) { | ~ ^ ~~~~~~~~ 1 warning generated. progs/bpf_qdisc_fifo.c:93:2: warning: comparison of integers of different signs: 'int' and '__u32' (aka 'unsigned int') [-Wsign-compare] 93 | bpf_for(i, 0, sch->q.qlen) { | ^ ~ ~~~~~~~~~~~ Should be noted that many more similar changes are still needed in order to be able to enable the -Wsign-compare flag since -Werror is enabled and would cause compilation of bpf selftests to fail. [1]. Link:torvalds/linux@495d2d8 Signed-off-by: Mehdi Ben Hadj Khelifa <[email protected]>
Upstream branch: e758657 |
308bf54
to
0807728
Compare
Pull request for series with
subject: selftests/bpf: Change variable types for -Wsign-compare
version: 4
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1013549